<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司代码" prop="factoryCode">
        <el-input
          v-model="queryParams.factoryCode"
          placeholder="请输入公司代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="公司名称" prop="factoryName">-->
<!--        <el-input-->
<!--          v-model="queryParams.factoryName"-->
<!--          placeholder="请输入公司名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产计划号" prop="proPlanNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.proPlanNo"-->
<!--          placeholder="请输入生产计划号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="订货号" prop="orderNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderNo"-->
<!--          placeholder="请输入订货号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产线" prop="proLine">-->
<!--        <el-input-->
<!--          v-model="queryParams.proLine"-->
<!--          placeholder="请输入生产线"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产日期" prop="proDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.proDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择生产日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产序列" prop="proSeq">-->
<!--        <el-input-->
<!--          v-model="queryParams.proSeq"-->
<!--          placeholder="请输入生产序列"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="顺序号" prop="serialNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.serialNumber"-->
<!--          placeholder="请输入顺序号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产序号" prop="proSerNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.proSerNum"-->
<!--          placeholder="请输入生产序号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发动机号" prop="engineNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.engineNo"-->
<!--          placeholder="请输入发动机号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="机体号" prop="eBodyNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.eBodyNo"-->
<!--          placeholder="请输入机体号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="整车订单号" prop="carOrderNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.carOrderNo"-->
<!--          placeholder="请输入整车订单号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="计划上线时间" prop="planUpLineTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.planUpLineTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择计划上线时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="计划下线时间" prop="planDownLineTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.planDownLineTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择计划下线时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="上线时间" prop="upLineTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.upLineTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择上线时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="下线时间" prop="downLineTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.downLineTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择下线时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="生产状态" prop="proState">-->
<!--        <el-input-->
<!--          v-model="queryParams.proState"-->
<!--          placeholder="请输入生产状态"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['procontrol:proLineMonitoring:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['procontrol:proLineMonitoring:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['procontrol:proLineMonitoring:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['procontrol:proLineMonitoring:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="proLineMonitoringList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="公司代码" align="center" prop="factoryCode" />
      <el-table-column label="公司名称" align="center" prop="factoryName" />
      <el-table-column label="生产计划号" align="center" prop="proPlanNo" />
      <el-table-column label="订货号" align="center" prop="orderNo" />
      <el-table-column label="生产线" align="center" prop="proLine" />
      <el-table-column label="生产日期" align="center" prop="proDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.proDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产序列" align="center" prop="proSeq" />
      <el-table-column label="顺序号" align="center" prop="serialNumber" />
      <el-table-column label="生产序号" align="center" prop="proSerNum" />
      <el-table-column label="发动机号" align="center" prop="engineNo" />
      <el-table-column label="机体号" align="center" prop="eBodyNo" />
      <el-table-column label="整车订单号" align="center" prop="carOrderNo" />
      <el-table-column label="计划上线时间" align="center" prop="planUpLineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planUpLineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划下线时间" align="center" prop="planDownLineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planDownLineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上线时间" align="center" prop="upLineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.upLineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下线时间" align="center" prop="downLineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.downLineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产状态" align="center" prop="proState" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['procontrol:proLineMonitoring:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['procontrol:proLineMonitoring:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生产过程管理总表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司代码" prop="factoryCode">
          <el-input v-model="form.factoryCode" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="factoryName">
          <el-input v-model="form.factoryName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="生产计划号" prop="proPlanNo">
          <el-input v-model="form.proPlanNo" placeholder="请输入生产计划号" />
        </el-form-item>
        <el-form-item label="订货号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订货号" />
        </el-form-item>
        <el-form-item label="生产线" prop="proLine">
          <el-input v-model="form.proLine" placeholder="请输入生产线" />
        </el-form-item>
        <el-form-item label="生产日期" prop="proDate">
          <el-date-picker clearable
            v-model="form.proDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择生产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产序列" prop="proSeq">
          <el-input v-model="form.proSeq" placeholder="请输入生产序列" />
        </el-form-item>
        <el-form-item label="顺序号" prop="serialNumber">
          <el-input v-model="form.serialNumber" placeholder="请输入顺序号" />
        </el-form-item>
        <el-form-item label="生产序号" prop="proSerNum">
          <el-input v-model="form.proSerNum" placeholder="请输入生产序号" />
        </el-form-item>
        <el-form-item label="发动机号" prop="engineNo">
          <el-input v-model="form.engineNo" placeholder="请输入发动机号" />
        </el-form-item>
        <el-form-item label="机体号" prop="eBodyNo">
          <el-input v-model="form.eBodyNo" placeholder="请输入机体号" />
        </el-form-item>
        <el-form-item label="整车订单号" prop="carOrderNo">
          <el-input v-model="form.carOrderNo" placeholder="请输入整车订单号" />
        </el-form-item>
        <el-form-item label="计划上线时间" prop="planUpLineTime">
          <el-date-picker clearable
            v-model="form.planUpLineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划上线时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划下线时间" prop="planDownLineTime">
          <el-date-picker clearable
            v-model="form.planDownLineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划下线时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上线时间" prop="upLineTime">
          <el-date-picker clearable
            v-model="form.upLineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上线时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="下线时间" prop="downLineTime">
          <el-date-picker clearable
            v-model="form.downLineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下线时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="生产状态" prop="proState">
          <el-input v-model="form.proState" placeholder="请输入生产状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProLineMonitoring, getProLineMonitoring, delProLineMonitoring, addProLineMonitoring, updateProLineMonitoring } from "@/api/procontrol/proLineMonitoring";

export default {
  name: "ProLineMonitoring",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产过程管理总表表格数据
      proLineMonitoringList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        factoryCode: null,
        factoryName: null,
        proPlanNo: null,
        orderNo: null,
        proLine: null,
        proDate: null,
        proSeq: null,
        serialNumber: null,
        proSerNum: null,
        engineNo: null,
        eBodyNo: null,
        carOrderNo: null,
        planUpLineTime: null,
        planDownLineTime: null,
        upLineTime: null,
        downLineTime: null,
        proState: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询生产过程管理总表列表 */
    getList() {
      this.loading = true;
      listProLineMonitoring(this.queryParams).then(response => {
        this.proLineMonitoringList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        factoryCode: null,
        factoryName: null,
        proPlanNo: null,
        orderNo: null,
        proLine: null,
        proDate: null,
        proSeq: null,
        serialNumber: null,
        proSerNum: null,
        engineNo: null,
        eBodyNo: null,
        carOrderNo: null,
        planUpLineTime: null,
        planDownLineTime: null,
        upLineTime: null,
        downLineTime: null,
        proState: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加生产过程管理总表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProLineMonitoring(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改生产过程管理总表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProLineMonitoring(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProLineMonitoring(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除生产过程管理总表编号为"' + ids + '"的数据项？').then(function() {
        return delProLineMonitoring(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('procontrol/proLineMonitoring/export', {
        ...this.queryParams
      }, `proLineMonitoring_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
